package com.todddavies.components.progressbar;

import com.example.android.navigationdrawerexample.R;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Shader;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * A sample activity showing some of the functions of the progress bar 
 */
public class main extends Activity {
	boolean running;
	ProgressWheel pw_two;
	int progress = 0;
	TextView t1,t2,t3;
	private Handler mHandler=new Handler(){

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			
			switch(msg.what){
			case 120:
				findViewById(R.id.imageView1).setVisibility(View.VISIBLE);
				findViewById(R.id.textView1).setVisibility(View.VISIBLE);
				findViewById(R.id.textView2).setVisibility(View.VISIBLE);
				break;
			case 167:
				
				findViewById(R.id.imageView2).setVisibility(View.VISIBLE);
				findViewById(R.id.textView3).setVisibility(View.VISIBLE);
				findViewById(R.id.textView4).setVisibility(View.VISIBLE);
				break;
			case 206:
			
				findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
				findViewById(R.id.textView5).setVisibility(View.VISIBLE);
				findViewById(R.id.textView6).setVisibility(View.VISIBLE);
				break;
			case 211:
				findViewById(R.id.imageView4).setVisibility(View.VISIBLE);
				findViewById(R.id.textView7).setVisibility(View.VISIBLE);
				findViewById(R.id.textView8).setVisibility(View.VISIBLE);
				break;
			case 225:
				findViewById(R.id.imageView5).setVisibility(View.VISIBLE);
				findViewById(R.id.textView9).setVisibility(View.VISIBLE);
				findViewById(R.id.textView10).setVisibility(View.VISIBLE);
				break;
			case 237:
				findViewById(R.id.imageView6).setVisibility(View.VISIBLE);
				findViewById(R.id.textView11).setVisibility(View.VISIBLE);
				findViewById(R.id.textView12).setVisibility(View.VISIBLE);
				break;
			case 312:
				findViewById(R.id.imageView7).setVisibility(View.VISIBLE);
				findViewById(R.id.textView13).setVisibility(View.VISIBLE);
				findViewById(R.id.textView14).setVisibility(View.VISIBLE);
				break;
				
			}
			super.handleMessage(msg);
		}
    	
    };

    private Handler mHandler1=new Handler(){

		@Override
		public void handleMessage(Message msg) {
			if(msg.what<=25)
				t1.setText(msg.what+"");
			if(msg.what<=60)
				t2.setText(msg.what+"");
			if(msg.what<=45)
				t3.setText(msg.what+"");
		}
    };
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.progress_wheel_activity);
       pw_two = (ProgressWheel) findViewById(R.id.progressBarTwo);
       t1=(TextView) findViewById(R.id.textView15);
       t2=(TextView) findViewById(R.id.textView16);
       t3=(TextView) findViewById(R.id.textView17);
        final Runnable r = new Runnable() {
        	
			public void run() {
				running = true;
				
				while(progress<361) {
					pw_two.incrementProgress();
					Message msg=new Message();
					switch(progress){
					case 120:
						msg.what=120;
						mHandler.sendMessage(msg);
						break;
					case 167:
						msg.what=167;
						mHandler.sendMessage(msg);
						break;
					case 206:
						msg.what=206;
						mHandler.sendMessage(msg);
						break;
					case 211:
						msg.what=211;
						mHandler.sendMessage(msg);
						break;
					case 225:
						msg.what=225;
						mHandler.sendMessage(msg);
						break;
					case 237:
						msg.what=237;
						mHandler.sendMessage(msg);
						break;
					case 312:
						msg.what=312;
						mHandler.sendMessage(msg);
						break;
					}
					progress++;
					System.out.println(progress);
					try {
						Thread.sleep(3);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				running=false;
				int t=0;
				while(t<=60)
				{
					t++;
					Message msg=new Message();
					msg.what=t;
					mHandler1.sendMessage(msg);
					try {
						Thread.sleep(10);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
			
        };
      
        progress = 0;
		pw_two.resetCount();
		Thread s = new Thread(r);
		s.start();
		
	}
	
	@Override
	public void onPause() {
		super.onPause();
		progress = 361;

		pw_two.resetCount();
		pw_two.setText("0");
	}
}
